// pages/study/study.js
import {StudyPaging} from "../../model/study-paging"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    articles: [],
    startMaskShow: true,
    loadingType: 'loading'
  },
  studyPaging: null,
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    this.initAllData()
  },
  async initAllData() {
    const paging = await StudyPaging.getLatestPaging()
    this.studyPaging = paging
    const data = await paging.getMoreData()
    if (!data) {
      return
    }
    this.setData({
      articles: data.accumulator
    })
    if (!data.moreData) {
      this.setData({
        loadingType: 'end'
      })
    }
  },
  onRuleTap() {
    wx.navigateTo({
      url: '/pages/studyRule/studyRule'
    })
  },
  onKnow() {
    this.setData({
      startMaskShow: false
    })
  },
  async onReachBottom() {
    const data = await this.studyPaging.getMoreData()
    if (!data) {
      return
    }
    this.setData({
      articles: data.accumulator
    })
    if (!data.moreData) {
      this.setData({
        loadingType: 'end'
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
